using System;
using System.Collections;
using System.Data;
using System.IO;
using System.Web.UI;
using SouthernLand.Common;

namespace SouthernLand.Controls
{
    public partial class Rotator : UserControl
    {
        public int stt;

        private ICollection CreateDataSource()
        {
            var dt = new DataTable();
            DataRow dr;

            dt.Columns.Add(new DataColumn("Hinh", typeof (string)));
            dt.Columns.Add(new DataColumn("HinhID", typeof (string)));

            string strUrlFile = Server.MapPath(Globals.ApplicationPath + "UserUpload/Rotator/");

            // Create a reference to the current directory.
            var di = new DirectoryInfo(strUrlFile);
            // Create an array representing the files in the current directory.
            FileInfo[] fi = di.GetFiles();

            //Response.Write("The following files exist in the current directory: <br>");
            // Print out the names of the files in the current directory.
            foreach (FileInfo fiTemp in fi)
            {
                stt = stt + 1;
                dr = dt.NewRow();

                dr["Hinh"] = fiTemp.Name;
                dr["HinhID"] = "Image" + stt;
                dt.Rows.Add(dr);
            }

            var dv = new DataView(dt);
            return dv;
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                // Load this data only once.
                rptRotator.DataSource = CreateDataSource();
                rptRotator.DataBind();
            }
        }
    }
}